#!/usr/bin/env python
# encoding: utf-8
# @author: Lin Han
# @contact: voldemort22@126.com
# @file: deprecated_app.py
# @time: 2021/5/13 16:51
# @desc:
import json

from fastapi import APIRouter, Request

data_board_router = APIRouter(
    prefix="/api/data_board",
    tags=["data_board"],
)


@data_board_router.get("/v1/history_clamp")
async def retrieve_history_clamp(request: Request):
    """
    ## 为数据看板提供历史夹具数据

    :param request:
    :param number:
    """
    data = await request.app.state.redis.get("data_board_history_clamp")
    data = json.loads(data)
    model = {"data": data, "status": 1}
    return model


@data_board_router.get("/v1/history_clamp_area")
async def retrieve_history_clamp_area(request: Request):
    """
    ## 为数据看板提供历史夹具数据

    :param request:
    :param number:
    """
    data = await request.app.state.redis.get("data_board_history_clamp")
    data = json.loads(data)
    data = list(set([i["area"] for i in data]))
    model = {"data": data, "status": 1}
    return model


@data_board_router.get("/v1/history_clamp_rps_number")
async def retrieve_history_clamp_rps_number(request: Request):
    """
    ## 为数据看板提供历史夹具rps点数量种类

    :param request:
    :param number:
    """
    data = await request.app.state.redis.get("data_board_history_clamp")
    data = json.loads(data)
    data = sorted(list(set([i["rpsNumber"] for i in data])))
    model = {"data": data, "status": 1}
    return model


@data_board_router.get("/v1/history_clamp_rps_type")
async def retrieve_history_clamp_rps_type(request: Request):
    """
    ## 为数据看板提供历史夹具rps点类型种类

    :param request:
    :param number:
    """
    data = await request.app.state.redis.get("data_board_history_clamp")
    data = json.loads(data)
    new_data = []
    for i in data:
        new_data.extend(i["rpsType"])
    data = sorted(list(set(new_data)))
    model = {"data": data, "status": 1}
    return model


@data_board_router.get("/v1/history_clamp_air_number")
async def retrieve_history_clamp_air_number(request: Request):
    """
    ## 为数据看板提供历史夹具气缸数量种类

    :param request:
    :param number:
    """
    data = await request.app.state.redis.get("data_board_history_clamp")
    data = json.loads(data)
    data = sorted(list(set([i["airNumber"] for i in data])))
    model = {"data": data, "status": 1}
    return model


@data_board_router.get("/v1/scene")
async def retrieve_scene_data_board(request: Request):
    """
    ## 为数据看板提供场景数据

    :param request:
    :param number:
    """
    data = await request.app.state.redis.get("data_board_scene")
    data = json.loads(data)
    model = {"data": data, "status": 1}
    return model
